*******************************************	   
************* TABLE A21 Degree centrality analysis
*******************************************	   

clear all
clear matrix
set more off

* Data preparation: 

// Load the original dataset
use "~/Dropbox/Replication_MVC/Datasets/datasets_analysis/panel_excombatientes.dta", clear 


// Calculate the count of members in each group and save it to a temporary dataset
tempfile membercount
sort year wartimenetwork
collapse (count) id, by(year wartimenetwork)
rename id members_total
save "`membercount'", replace

// Load the original dataset
use "~/Dropbox/Replication_MVC/Datasets/datasets_analysis/panel_excombatientes.dta", clear 

// Merge the member count information back into the original dataset
merge m:1 year wartimenetwork using "`membercount'"
drop _merge

// Remove the temporary dataset
erase "`membercount'"

eststo clear
set more off


* generate var members_total
sum members_total
generate degree_centrality_r = (members_total-r(mean))/r(sd)

eststo clear
set more off

reghdfe NdeCapturasenFlagrancia degree_centrality_r, absorb(time_t) vce(cluster id)
summ NdeCapturasenFlagrancia if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

reghdfe NdeCapturasenFlagrancia degree_centrality_r, absorb(origmun) vce(cluster id)
estadd local ALLFE = "$\checkmark$"
summ NdeCapturasenFlagrancia if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

reghdfe NdeCapturasenFlagrancia degree_centrality_r, absorb(origmun wartimenetwork) vce(cluster id)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
summ NdeCapturasenFlagrancia if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo 

reghdfe NdeCapturasenFlagrancia degree_centrality_r age female indigenous black, absorb(origmun wartimenetwork) vce(cluster id)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
estadd local CO = "$\checkmark$"
summ NdeCapturasenFlagrancia if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo 

reghdfe NdeCapturasCrucePONAL degree_centrality_r, absorb(time_t) vce(cluster id)
summ NdeCapturasCrucePONAL if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

reghdfe NdeCapturasCrucePONAL degree_centrality_r, absorb(origmun) vce(cluster id)
estadd local ALLFE = "$\checkmark$"
summ NdeCapturasCrucePONAL if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo

reghdfe NdeCapturasCrucePONAL degree_centrality_r, absorb(origmun wartimenetwork) vce(cluster id)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
summ NdeCapturasCrucePONAL if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo 

reghdfe NdeCapturasCrucePONAL degree_centrality_r age female indigenous black, absorb(origmun wartimenetwork) vce(cluster id)
estadd local ALLFE = "$\checkmark$"
estadd local TT = "$\checkmark$"
estadd local CO = "$\checkmark$"
summ NdeCapturasCrucePONAL if e(sample) ==1
estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
estadd local SDDep = trim("`: display %12.4fc `r(sd)''")
eststo 

* Table A21
esttab est* using "~/Dropbox/Replication_MVC/Paper_tables/TableA21.tex", se ///
	   star(* 0.10 ** 0.05 *** 0.01 ) ///
	   stats(meanDep SDDep N ALLFE TT  CO, fmt(%12.4fc %12.4fc  %12.0fc %12.0fc %12.0fc %12.0fc  %12.0fc ) ///
	   label("\small Mean of Outcome" "\small S.D of Outcome" "\small Observations" "\small Municipality FE" "\small Wartime FE"  ///
	   "\small Individual Covariates" )) ///
	   keep(degree_centrality_r) /// 
	   varlabels(degree_centrality_r "Degree Centrality") ///
	   ti("Degree Centrality and Criminality - Full Model Results") ///	  
	   replace 

	   
* Table A40
// esttab est* using "~/Dropbox/Replication_MVC/Paper_tables/TableA40.tex", se ///
// 	   star(* 0.10 ** 0.05 *** 0.01 ) ///
// 	   stats(meanDep SDDep N ALLFE TT  CO, fmt(%12.4fc %12.4fc  %12.0fc %12.0fc %12.0fc %12.0fc  %12.0fc ) ///
// 	   label("\small Mean of Outcome" "\small S.D of Outcome" "\small Observations" "\small Municipality FE" "\small Wartime FE"  ///
// 	   "\small Individual Covariates" )) ///
// 	   varlabels(degree_centrality_r "Degree Centrality") ///
// 	   ti("Degree Centrality and Criminality - Full Model Results") ///	  
// 	   replace 	   
